﻿using System;
using Entity.IRepository.Project;
using Entity.ProjectEnt;
using System.Collections.Generic;
using System.Data.Entity;
using ZFine.Data;

namespace Logic.Repository.Project
{
    public class CarriageBoxRepository : RepositoryBase<CarriageBoxEntity>, ICarriageBoxRepository
    {
        public int insertCarriageBoxList(List<CarriageBoxEntity> carriageBoxList)
        {
            foreach (var entity in carriageBoxList)
            {

                dbcontext.Entry<CarriageBoxEntity>(entity).State = EntityState.Added;
            }
            return dbcontext.SaveChanges();
        }

        public void UpdateCarBoxAndInsertCarriageInfoLog(List<CarriageBoxEntity> carriageBoxList, List<CarriageInfoLogEntity> carriageInfoLogs)
        {
            try
            {
                foreach (var entity in carriageBoxList)
                {

                    dbcontext.Entry<CarriageBoxEntity>(entity).State = EntityState.Modified;
                }
                foreach (var carriageInfoLogEntity in carriageInfoLogs)
                {

                    dbcontext.Entry<CarriageInfoLogEntity>(carriageInfoLogEntity).State = EntityState.Added;
                }
                dbcontext.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

        }

        public int UpdateList(List<CarriageBoxEntity> insertObjList)
        {
            try
            {
                foreach (var entity in insertObjList)
                {
                    dbcontext.Entry<CarriageBoxEntity>(entity).State = EntityState.Modified;
                }
               return dbcontext.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

        }
    }
}
